<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>注册</title>
    <link rel="stylesheet" href="//g.alicdn.com/msui/sm/0.6.2/css/sm.min.css">
    <link rel="stylesheet" href="//g.alicdn.com/msui/sm/0.6.2/css/sm-extend.min.css">
</head>
<body>
<div align="center">
    <h1>注册</h1>
    <label>请输入用户名</label>
    <input type="text" id="username" placeholder="用户名"><br/>
    <label>请输入密码</label>
    &nbsp;&nbsp;&nbsp;<input type="password" id="password" placeholder="密码"><br/>
    <input type="submit" value="注册" id="reg">
</div>

</body>
<script type='text/javascript' src='//g.alicdn.com/sj/lib/zepto/zepto.min.js' charset='utf-8'></script>
<script type='text/javascript' src='//g.alicdn.com/msui/sm/0.6.2/js/sm.min.js' charset='utf-8'></script>
<script type='text/javascript' src='//g.alicdn.com/msui/sm/0.6.2/js/sm-extend.min.js' charset='utf-8'></script>
<script>
    // $("#reg").click(function () {
    //     let user={};
    //     user.username = $("#username").val();
    //     user.password = $("#password").val();
    //     $.ajax({
    //         url:'user/reg',
    //         type:'post',
    //         dataType:'json',
    //         contentType:'application/json',
    //         data:JSON.stringify(user),
    //         success:function (data) {
    //             if(data.success){
    //                 $.toast("注册成功");
    //                 window.location.href='index.html';
    //             }else {
    //                 $.toast(data.errMsg);
    //             }
    //
    //         }
    //     });
    // })

    $("#reg").click(function () {
        $.ajax({
            url: 'user/reg',
            type: 'post',
            data: {
                username: $("#username").val(),
                password: $("#password").val()
            },
            success: function (data) {
                if (data.success) {
                    window.location.href = 'index.html';
                    $.toast("注册成功,请登录");

                } else {
                    $.toast(data.errMsg);
                }

            }
        });
    })

</script>
</html>